package com.wys.mall.ware.service.impl;

import com.wys.common.utils.MyStrUtil;
import com.wys.mall.ware.entity.WareSkuEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wys.common.utils.PageUtils;
import com.wys.common.utils.Query;

import com.wys.mall.ware.dao.PurchaseDetailDao;
import com.wys.mall.ware.entity.PurchaseDetailEntity;
import com.wys.mall.ware.service.PurchaseDetailService;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<PurchaseDetailEntity> queryWrapper = new QueryWrapper<>();
        String key = String.valueOf(params.get("key"));
        if (MyStrUtil.isNotEmpty(key)) {
            queryWrapper.and(w -> {
                w.eq("purchase_id", key).or().like("sku_id", key);
            });
        }
        String status = String.valueOf(params.get("status"));
        if (MyStrUtil.isNotBlank(status)) {
            queryWrapper.eq("status", status);
        }

        String wareId = String.valueOf(params.get("wareId"));
        if (MyStrUtil.isNotBlank(wareId)) {
            queryWrapper.eq("ware_id", wareId);
        }

        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<PurchaseDetailEntity> listDetailByPurchaseId(Long id) {
        return this.baseMapper.selectList(new QueryWrapper<PurchaseDetailEntity>().eq("purchase_id",id));
    }

}